# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Sui Libin <bygreencn@gmail.com>

_realname=libxlsxwriter
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.2
pkgrel=1
pkgdesc="A C library for creating Excel XLSX files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/jmcnamara/libxlsxwriter"
license=("spdx:BSD-2-Clause")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=("https://github.com/jmcnamara/libxlsxwriter/archive/v${pkgver}/${_realname}-v${pkgver}.tar.gz")
sha256sums=('8ab0aced8a6e82f12f567b48d2cb3ca7b925893126607a619666da467e9ac14f')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    "${extra_config[@]}" \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_TESTS=OFF \
    -DBUILD_EXAMPLES=OFF \
    -DUSE_SYSTEM_MINIZIP=OFF \
    -S "${_realname}-${pkgver}" \
    -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE.txt" "${pkgdir}/${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
